package com.njtoyo.taxi.admin.rest.controller.business.operation_rule.designated;

import com.njtoyo.taxi.admin.mapper.master.enums.DriverRegionServiceArrangementCategory;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.DesignatedChargeWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.DriverServiceArrangementAddUpdateWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.DriverServiceArrangementWrapper;
import com.njtoyo.taxi.admin.service.business.operation_rule.DriverServiceArrangementService;
import com.njtoyo.taxi.entity.backend.AdminUser;
import com.taxi.entity.common.RestResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "代驾分成规则配置", tags = "代驾分成规则配置")
@RequestMapping("business/operation-rule/designated/divide")
public class DesignatedDivideRuleController {

    @Autowired
    private DriverServiceArrangementService driverServiceService;


    /**
     * 代驾分成规则列表
     *
     * @param adminUser
     * @return
     */
    @GetMapping("/list")
    RestResult list(@ModelAttribute("admin") AdminUser adminUser, DriverServiceArrangementWrapper wrapper) {
        return driverServiceService.getPageByCategory(adminUser, wrapper);
    }


    @PostMapping("/add")
    RestResult add(@ModelAttribute("admin") AdminUser adminUser, @RequestBody DriverServiceArrangementAddUpdateWrapper wrapper) {
        wrapper.setServiceCategory(DriverRegionServiceArrangementCategory.designated_driver_earning);
        return driverServiceService.add(wrapper);
    }

    @PostMapping("/update")
    RestResult update(@ModelAttribute("admin") AdminUser adminUser, @RequestBody DriverServiceArrangementAddUpdateWrapper wrapper) {
        return driverServiceService.update(wrapper);
    }


    @PostMapping("/updateIsOpen")
    RestResult updateIsOpen(@ModelAttribute("admin") AdminUser adminUser, @RequestBody DesignatedChargeWrapper wrapper) {
        return driverServiceService.updateDesigantedRuleIsOpen(wrapper);
    }


    @DeleteMapping("/delete/{id}")
    RestResult delete(@PathVariable("id") Long id) {
        return driverServiceService.deleteById(id);
    }
}
